﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.UC.订单.service;
using DXApplicationTangche.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.款式管理.service
{
    public class 款式Service
    {
        /// <summary>
        /// 根据styleId找尺寸（坚山尺码）
        /// </summary>
        /// <param name="styleId"></param>
        /// <returns></returns>
        public static KashiyamaStyleSizeDTO getStyleInfoById(int styleId)
        {
            return
                FunctionHelper.JsonDeserialization<KashiyamaStyleSizeDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/style/getStyleInfoById?styleId=" + styleId
                    )
                );
        }
        /// <summary>
        /// 取坚山尺寸表
        /// </summary>
        /// <param name="fitCd"></param>
        /// <param name="sizeCd"></param>
        /// <param name="sizeGroupCd"></param>
        /// <param name="styleId"></param>
        /// <returns></returns>
        public static List<SizeKashiyamaResultDTO> getSizeKashiyamaResult(String fitCd,String sizeCd,String sizeGroupCd,String styleId)
        {
            return
                FunctionHelper.JsonDeserialization<List<SizeKashiyamaResultDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/style/getSizeKashiyamaResult?fitCd=" + fitCd 
                                    + "&sizeCd=" + sizeCd 
                                    + "&sizeGroupCd=" + sizeGroupCd 
                                    + "&styleId=" + styleId
                    )
                );
        }
        /// <summary>
        /// 新建款式
        /// </summary>
        /// <param name="styleInfoDto"></param>
        /// <returns></returns>
        public static StyleInfoDto createStyleInfo(String catagoryId,StyleInfoDto styleInfoDto)
        {
            return
                FunctionHelper.JsonDeserialization<StyleInfoDto>(
                    RestCall.PostHttp(
                        URL.接口url + "/style/createStyleInfoByCatagoryId?catagoryId=" + catagoryId,
                        FunctionHelper.JsonSerialization(styleInfoDto)
                    )
                );
        }
        /// <summary>
        /// 新建款式
        /// </summary>
        /// <param name="styleInfomationDto"></param>
        /// <returns></returns>
        public static DTO返回值判断 createStyleInfoWithStyleInformationDTO(StyleInformationDTO styleInformationDTO)
        {
            return
                FunctionHelper.JsonDeserialization<DTO返回值判断>(
                    RestCall.PostHttp(
                        URL.接口url + "/style/createStyleInfoWithStyleInformationDTO",
                        FunctionHelper.JsonSerialization(styleInformationDTO)
                    )
                );
        }

        /// <summary>
        /// 上传款式图片
        /// </summary>
        /// <param name="styleId"></param>
        /// <param name="ofd"></param>
        /// <returns></returns>
        public static String 上传款式图(string styleId, OpenFileDialog ofd)
        {
            return
                FileService.UploadRequest(
                    URL.接口url + "/image/uploadStyleImage?styleId=" + styleId,
                    ofd.FileName,
                    Path.GetFileName(ofd.FileName),
                    "multipartFile"
                    );
        }

        /// <summary>
        /// get款式图片
        /// </summary>
        /// <param name="styleId"></param>
        /// <returns></returns>
        public static String get款式图(string styleId)
        {
            return
                URL.图片url + URL.款式图片路径 + RestCall.httpGetMethod(URL.接口url + "/image/getStyleImagePathByStyleId?styleId=" + styleId);
        }

        /// <summary>
        /// 获取款式类别一览
        /// </summary>
        /// <returns></returns>
        public static List<StyleCategoryDTO> get款式类别()
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<List<StyleCategoryDTO>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/style/getStyleCategoryAll"
                            )
                        );
            }
            catch 
            {
                return new List<StyleCategoryDTO>();
            }
        }
        /// <summary>
        /// 获取所有款式一览
        /// </summary>
        /// <returns></returns>
        public static List<款式维护记录> get全部款式()
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<List<款式维护记录>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/style/findStyleIndexAll"
                            )
                        );
            }
            catch (Exception)
            {
                return new List<款式维护记录>();
            }
        }
        /// <summary>
        /// 根据id找款式
        /// </summary>
        /// <param name="sysStyleId"></param>
        /// <returns></returns>
        public static StyleInfoDto getStyleInfoByStyleId(int sysStyleId)
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<StyleInfoDto>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/style/getStyleInfoByStyleId?sysStyleId=" + sysStyleId
                            )
                        );
            }
            catch (Exception)
            {
                return new StyleInfoDto();
            }
        }

        /// <summary>
        /// 取字典数据
        /// </summary>
        /// <returns></returns>
        public static List<ItemDictDTO> getItemDictByItemCd(String itemCd)
        {
            return
                FunctionHelper.JsonDeserialization<List<ItemDictDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/customer/getItemDictByItemCd?itemCd=" + itemCd
                        )
                    );
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public class ItemDictDTO
    {
        public int item_id { get; set; }
        public String parent_item_cd { get; set; }
        public String itemCd { get; set; }
        public String itemValue { get; set; }
        public String item_sort { get; set; }
        public String item_real_value { get; set; }
        public String item_name_cn { get; set; }
        public String item_short_name_cn { get; set; }
        public String item_name_en { get; set; }
        public String item_short_name_en { get; set; }
        public String item_name_jp { get; set; }
        public String item_short_name_jp { get; set; }
        public String remarks { get; set; }
        public int enable_flag { get; set; }
        public int delete_flag { get; set; }
        public int version { get; set; }
        public DateTime create_date { get; set; }
        public DateTime update_date { get; set; }
        public int create_user { get; set; }
        public int update_user { get; set; }
        public ItemDictDTO()
        {

        }
    }
    /// <summary>
    /// 坚山相关款式信息及尺码
    /// </summary>
    public class KashiyamaStyleSizeDTO
    {
        public StyleInfoDto styleInfoDto { get; set; } = new StyleInfoDto();
        public List<SizeFitKashiyamaDTO> sizeFitKashiyamaDTOS { get; set; } = new List<SizeFitKashiyamaDTO>();
        public KashiyamaStyleSizeDTO()
        {

        }
    }
    /// <summary>
    /// 坚山相关款式尺码
    /// </summary>
    public class SizeFitKashiyamaDTO
    {
        public String sizeCd { get; set; }
        public String sizeCdShort { get; set; }
        public SizeFitKashiyamaDTO()
        {

        }
    }
    /// <summary>
    /// 坚山尺寸表
    /// </summary>
    public class SizeKashiyamaResultDTO
    {
        public String itemCd { get; set; }
        public String itemValue { get; set; }
        public String itemFitValue { get; set; }
        public String itemNameCn { get; set; }
        public String leastreasonable { get; set; }
        public String maxreasonable { get; set; }
        public SizeKashiyamaResultDTO()
        {

        }
    }

    public class StyleInfoDto
    {
        public int sysStyleId { get; set; }//
        public int shopId { get; set; }//
        public String styleNo { get; set; }//
        public int customerCountId { get; set; }//
        public String styleCd { get; set; }//
        public String styleKbn { get; set; }//
        public String styleSource { get; set; }//
        public String styleCategoryCd { get; set; }//
        public String styleDressCategory { get; set; }//
        public String styleDesignType { get; set; }//
        public String stylePublishCategoryCd { get; set; }//
        public int refStyleId { get; set; }//
        public String styleNameCn { get; set; }//
        public String styleNameEn { get; set; }//
        public String styleFitCd { get; set; }//
        public String sytleYear { get; set; }//
        public String sytleSeason { get; set; }//
        public String sytleFabricId { get; set; }//
        public String sytleFabricNo { get; set; }//
        public String styleComposition { get; set; }//
        public String styleDescribe { get; set; }//
        public String styleColorCd { get; set; }//
        public String styleColorName { get; set; }//
        public String styleSizeGroupCd { get; set; }//
        public String styleSizeCd { get; set; }//
        public String styleMakeType { get; set; }//
        public String styleFitBodyType { get; set; }//
        public String styleSexCd { get; set; }//
        public String styleStandard { get; set; }//
        public String styleBarCode { get; set; }//
        public DateTime styleDesignerDate { get; set; }//
        public int styleDesigner { get; set; }//
        public Double styleMaterialNumber { get; set; }//
        public Double styleDesignPrice { get; set; }//
        public Double styleFactoryTotalPrice { get; set; }//
        public Double styleShopTotalPrice { get; set; }//
        public String remarks { get; set; }//
        public int enableFlag {get;set;}//
        public int deleteFlag{get;set;}//
        public int version {get;set;}//
        public DateTime createDate { get; set; }//
        public DateTime updateDate { get; set; }//
        public int createUser { get; set; }//
        public int updateUser { get; set; }//
        public String coverPhotoPath { get; set; }//
        public StyleInfoDto()
        {

        }

    }

    public class StyleInformationDTO
    {
        public int refStyleId { get; set; }// styleId
        public String styleCode { get; set; }  //  款号
        public String styleName { get; set; }  //  款名
        public String sytleYear { get; set; }  //  年份
        public String sytleSeason { get; set; }  //  季节
        public String catagoryId { get; set; } //  款式类别id
        public String catagoryCd { get; set; } //  款式类别code
        public String mnemonic { get; set; }   //  员工
        public StyleInformationDTO()
        {

        }
        
        public StyleInformationDTO(string styleCode, string styleName, string sytleYear, string sytleSeason, string catagoryId, string catagoryCd)
        {
            this.styleCode = styleCode;
            this.styleName = styleName;
            this.sytleYear = sytleYear;
            this.sytleSeason = sytleSeason;
            this.catagoryId = catagoryId;
            this.catagoryCd = catagoryCd;
        }
        public StyleInformationDTO build(String mnemonic)
        {
            this.mnemonic = mnemonic;
            return this;
        }
    }

}
